package com.wuyou.simple;

/**
 * 面试题 01.09. 字符串轮转
 */
public class IsFlipedString {


    public static void main(String[] args) {
        IsFlipedString isFlipedString = new IsFlipedString();
        String s1 = "PvcvpkpHwaXQxpgGzURBvHRMvCsCPPmlKBSzXDWSvrxLBPdAvRpgcIwNOVQDdwPIElrAFqmb";
        String s2 = "SvrxLBPdAvRpgcIwNOVQDdwPIElrAFqmbPvcvpkpHwaXQxpgGzURBvHRMvCsCPPmlKBSzXDW";
        System.out.println(isFlipedString.solution_1(s1, s2));
    }


    public boolean solution_1(String s1, String s2) {
        if (s1.equals(s2)) return true;
        if (s1.length() != s2.length()) return false;

        String str = "";
        String tempStr = s2;
        char c = s1.charAt(0);
        while (true) {
            int index = tempStr.indexOf(String.valueOf(c));
            if (index == -1) return false;

            String temp = tempStr.substring(index, tempStr.length());
            str += tempStr.substring(0, index);
            if ((temp + str).equals(s1)) return true;
            tempStr = tempStr.substring(index + 1, tempStr.length());    // 截取当前 首字母
            str += String.valueOf(c);
        }
    }
}
